import requests
import json

if __name__ == '__main__':
    # 1.指定url
    url = 'http://www.kfc.com.cn/kfccda/ashx/GetStoreList.ashx?op=keyword'
    # 2.post请求参数处理
    word = input('enter a word:')
    data = {
        'cname': '',
        'pid': '',
        'keyword': word,
        'pageIndex': '1',
        'pageSize': '10',
    }
    # 3.进行UA伪装
    headers = {
        'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.131 Safari/537.36'
    }
    # 4.请求发送
    response = requests.post(url=url, data=data, headers=headers)
    # 5.持久化存储
    page_text = response.text
    fileName = word+'.txt'
    with open(fileName, 'w', encoding='utf-8') as fp:
        fp.write(page_text)
    print('over!!!')